package com.intgrt.manager.ctrl;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.intgrt.manager.entity.SysMenuBtn;
import com.intgrt.manager.entity.SysUser;
import com.intgrt.manager.service.SysMenuBtnService;
import com.intgrt.manager.util.ProjectConstants;

@Controller
public class SysMenuBtnCtrl {

	@Autowired
	private SysMenuBtnService service;
	private static final String MENU_ID = "4";

	@RequestMapping(value = "/menubtn", method = { RequestMethod.GET })
	public String index(HttpServletRequest request) {
		String menuid = request.getParameter("mid");
		SysUser curuser = (SysUser)request.getSession().getAttribute(ProjectConstants.SESSION_USER);
		String btnids = "";
		try {
			btnids = curuser.getMenuButtons().getString(MENU_ID);
		} catch (Exception e) {
			btnids = "";
		}
		JSONArray btnlist = service.getMenuBtns(curuser.getId(), MENU_ID, btnids);
		request.setAttribute("btnlist", btnlist);
		request.setAttribute("menuid", menuid);
		return "sysmenubtn";
	}
	@ResponseBody
	@RequestMapping(value="/d/menubtnlist" , method={RequestMethod.POST})
	public String list(HttpServletRequest request){
		String menuid = request.getParameter("menuid");
		String page = request.getParameter("page");
		String rows = request.getParameter("rows");
		SysMenuBtn entity = new SysMenuBtn();
		entity.setMenuid(menuid);
		entity.setPage(Integer.parseInt(page));
		entity.setRows(Integer.parseInt(rows));
		return service.getList(entity);
	}
	@ResponseBody
	@RequestMapping(value="/d/menubtnsave" , method={RequestMethod.POST})
	public String menuSave(HttpServletRequest request, SysMenuBtn entity){
		return service.saveEntity(entity);
	}
	@ResponseBody
	@RequestMapping(value="/d/menubtnedit" , method={RequestMethod.POST})
	public String menuEdit(HttpServletRequest request, SysMenuBtn entity){
		return service.editEntity(entity);
	}
	@ResponseBody
	@RequestMapping(value="/d/menubtndel" , method={RequestMethod.POST})
	public String menuDel(HttpServletRequest request){
		String ids = request.getParameter("ids");
		return service.delEntity(ids);
	}

}